package com.googlecode.imanager.client;

import com.googlecode.imanager.client.layout.BoxLayout;
import com.googlecode.imanager.client.layout.Overflow;
import com.googlecode.imanager.client.layout.ScrollBox;
import com.googlecode.imanager.client.style.Orientation;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class Table extends ScrollBox /*implements Focusable, HasSelection*/ {

    private static final long serialVersionUID = 1L;
    
    public Table() {
        super();
        setOrientation(Orientation.VERTICAL);
    }

    public Table(Container parent) {
        this();
        setParent(parent);
    }
    
    public void setOrientation(Orientation orientation) {
        if (orientation == null) {
            orientation = Orientation.DEFAULT;
        }
        
        setLayout(BoxLayout.getInstance(orientation));
        
        if (orientation == Orientation.VERTICAL){
            getHorizontalScroller().setOverflow(Overflow.HIDDEN);
            if (getVerticalScroller().getOverflow() == Overflow.HIDDEN){
                getVerticalScroller().setOverflow(Overflow.AUTO);
            }
        } else {
            getVerticalScroller().setOverflow(Overflow.HIDDEN);
            if (getHorizontalScroller().getOverflow() == Overflow.HIDDEN){
                getHorizontalScroller().setOverflow(Overflow.AUTO);
            }
        }
    }

    public Orientation getOrientation() {
        if (getLayout() == BoxLayout.getInstance(Orientation.VERTICAL)){
            return Orientation.VERTICAL;
        }
        if (getLayout() == BoxLayout.getInstance(Orientation.HORIZONTAL)){
            return Orientation.HORIZONTAL;
        }
        return null;
    }
    
    // TODO por default um Panel inserido aqui terá isSelectable=true

    @Override
    public Table clone() {
        return (Table) super.clone();
    }

}
